package org.skjworld.wiki2 ;

import java.io.IOException;
import javax.servlet.http.*;

@SuppressWarnings("serial")
public class Wiki2Servlet extends HttpServlet
{
	// Creates an object
	public void doPost(HttpServletRequest req, HttpServletResponse resp)throws IOException
	{
		String uri 		= req.getRequestURI();
		String website 	= req.getServerName() ;
		
		if(uri.compareTo("CREATE_USER") == 0)
		{
			if(isTrustedSite(website) == true)
			{
				if(isAdminKeyValid("SKJ101ANKIT") == true)
				{
					
				}
			}
		}
		else if(uri.compareTo("CREATE_USER_GROUP") == 0)
		{
			if(isTrustedSite(website) == true)
			{
				
			}
		}
		else if(uri.compareTo("CREATE_OBJECTS") == 0)
		{
			if(isTrustedSite(website) == true)
			{
				
			}
		}
		else if(uri.compareTo("CREATE_LINKS") == 0)
		{
			if(isTrustedSite(website) == true)
			{
				
			}
		}
	}
	
	// Retrieves an object
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
	{
		resp.setContentType("text/plain");
		resp.getWriter().println("Hello, world");
	}
	
	// Updates an object
	public void doPut(HttpServletRequest req, HttpServletResponse resp)throws IOException
	{
		
	}
	
	// Deletes an object
	public void doDelete(HttpServletRequest req, HttpServletResponse resp)throws IOException
	{
		
	}
	
	// Checks whether a site is trusted or not
	private boolean isTrustedSite(String website)
	{
		if(website.compareTo("www.skjworld.com") == 0 && website.compareTo("skjwiki2.appspot.com") == 0 && website.compareTo("localhost") == 0)
		{
			return true ;
		}
		else
		{
			return false ;
		}
	}
	
	// Checks whether the key sent with API call contains the valid Admin Key
	private boolean isAdminKeyValid(String adminKey)
	{
		if(adminKey.compareTo("SKJ101ANKIT") == 0)
		{
			return true ;
		}
		else
		{
			return false ;
		}
	}
}
